/**
 * app 接口 request 实例
 * */
// import axios from 'axios'
import Request from './utils/extendRequest.js'
import store from '@/store'
import { errorInterceptors } from './interceptors'

import ENV from '@/config/ENV.js'
const app = new Request()
app.config.timeout = 50000
app.config.baseURL = ENV.apiBaseURL
app.config.header.platform = 'weChat_applet'
// content-type 全小写
app.config.header['content-type'] = 'application/json'
app.interceptors.request.use(config => {
  config.header.Authorization = store.getters.isLogin ? `Bearer ${store.state.appToken}` : ''
  return config
}, error => {
  return Promise.reject(error)
})
app.interceptors.response.use(
  response => {
    return response
  },
  error => {
    errorInterceptors(error)
    return Promise.reject(error)
  }
)

export default app